package com.owbtgad.common

import android.app.ProgressDialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import com.google.android.material.progressindicator.CircularProgressIndicator

/**86097801
 * 描述：
 */
class MyProgressDialog(context: Context?) : ProgressDialog(context) {
    private var mWidth = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_progress_dialog)
        val window = window
        window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    }

    override fun show() {
        super.show()
        try {
            window!!.decorView.post {
                if (mWidth != 0) {
                    val window = window
                    val lp = window!!.attributes
                    lp.width = mWidth
                    window.attributes = lp
                } else {
                    mWidth = window!!.decorView.width
                }
            }
        } catch (e: Exception) {
        }
        val progressIndicator: CircularProgressIndicator = findViewById(R.id.progress_indicator)
        if (!progressIndicator.isIndeterminate) {
            // Cannot set to indeterminate if the indicator is visible. Immediately set to
            // INVISIBLE instead of waiting for animation from calling hide().
            progressIndicator.visibility = View.INVISIBLE
            progressIndicator.isIndeterminate = true
        }
        progressIndicator.show()
    }


    init {
        setCancelable(true)
        setCanceledOnTouchOutside(false)
    }
}